home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
076-100
/
disk_099
/
a-render
/
build_objects
/
balpha.c
next >
Wrap
C/C++ Source or Header
|
1992-05-06
|
15KB
|
475 lines
/*
**
** A 'C' Source File Demonstrating How to Build Objects for A-Render
**
*/
#include <stdio.h>
/* Constants to dimension our arrays */
#define OBJ_VERT_ARRAY_SIZE 46
#define OBJ_POLY_ARRAY_SIZE 41
#define OBJ_POLY_VERT_ARRAY_SIZE 9
/* Define a data structure for use */
struct Object {
int id;
int type;
int polygon_count;
int vertice_count;
int polygon_vertice_count[OBJ_POLY_ARRAY_SIZE];
int vertice_list[OBJ_POLY_ARRAY_SIZE] [OBJ_POLY_VERT_ARRAY_SIZE];
float vertice_x[OBJ_VERT_ARRAY_SIZE];
float vertice_y[OBJ_VERT_ARRAY_SIZE];
float vertice_z[OBJ_VERT_ARRAY_SIZE];
};
/* Define a variable named 'object', of a structure of type 'Object' */
struct Object object;
main()
{
FILE *fopen(), *fp;
int polygon_id,
vertice_id,
vlist_id,
this_object_id = 1;
/************ Start your changes here! **********/
/* Be sure to set these */
/* two values. */
object.polygon_count = 28;
object.vertice_count = 40;
/* Now just explicitly set up the XYZ values */
/* for our object vertice points. (40 vertices) */
object.vertice_x [1] = -3.75;
object.vertice_y [1] = -4.;
object.vertice_z [1] = -.5;
object.vertice_x [2] = -3.75;
object.vertice_y [2] = -3.5;
object.vertice_z [2] = -.5;
object.vertice_x [3] = -3.;
object.vertice_y [3] = -3.5;
object.vertice_z [3] = -.5;
object.vertice_x [4] = 1.25;
object.vertice_y [4] = 2.75;
object.vertice_z [4] = -.5;
object.vertice_x [5] = 1.25;
object.vertice_y [5] = 1.5;
object.vertice_z [5] = -.5;
object.vertice_x [6] = -2.;
object.vertice_y [6] = -3.5;
object.vertice_z [6] = -.5;
object.vertice_x [7] = -1.25;
object.vertice_y [7] = -3.5;
object.vertice_z [7] = -.5;
object.vertice_x [8] = -1.25;
object.vertice_y [8] = -4.;
object.vertice_z [8] = -.5;
object.vertice_x [9] = 2.;
object.vertice_y [9] = 4.;
object.vertice_z [9] = -.5;
object.vertice_x [10] = 3.;
object.vertice_y [10] = 4.;
object.vertice_z [10] = -.5;
object.vertice_x [11] = 3.;
object.vertice_y [11] = -3.5;
object.vertice_z [11] = -.5;
object.vertice_x [12] = 3.75;
object.vertice_y [12] = -3.5;
object.vertice_z [12] = -.5;
object.vertice_x [13] = 3.75;
object.vertice_y [13] = -4.;
object.vertice_z [13] = -.5;
object.vertice_x [14] = .5;
object.vertice_y [14] = -4.;
object.vertice_z [14] = -.5;
object.vertice_x [15] = .5;
object.vertice_y [15] = -3.5;
object.vertice_z [15] = -.5;
object.vertice_x [16] = 1.25;
object.vertice_y [16] = -3.5;
object.vertice_z [16] = -.5;
object.vertice_x [17] = -1.;
object.vertice_y [17] = -2.;
object.vertice_z [17] = -.5;
object.vertice_x [18] = -.5;
object.vertice_y [18] = -1.;
object.vertice_z [18] = -.5;
object.vertice_x [19] = 1.25;
object.vertice_y [19] = -1.;
object.vertice_z [19] = -.5;
object.vertice_x [20] = 1.25;
object.vertice_y [20] = -2.;
object.vertice_z [20] = -.5;
object.vertice_x [21] = -3.75;
object.vertice_y [21] = -4.;
object.vertice_z [21] = .5;
object.vertice_x [22] = -3.75;
object.vertice_y [22] = -3.5;
object.vertice_z [22] = .5;
object.vertice_x [23] = -3.;
object.vertice_y [23] = -3.5;
object.vertice_z [23] = .5;
object.vertice_x [24] = 1.25;
object.vertice_y [24] = 2.75;
object.vertice_z [24] = .5;
object.vertice_x [25] = 1.25;
object.vertice_y [25] = 1.5;
object.vertice_z [25] = .5;
object.vertice_x [26] = -2.;
object.vertice_y [26] = -3.5;
object.vertice_z [26] = .5;
object.vertice_x [27] = -1.25;
object.vertice_y [27] = -3.5;
object.vertice_z [27] = .5;
object.vertice_x [28] = -1.25;
object.vertice_y [28] = -4.;
object.vertice_z [28] = .5;
object.vertice_x [29] = 2.;
object.vertice_y [29] = 4.;
object.vertice_z [29] = .5;
object.vertice_x [30] = 3.;
object.vertice_y [30] = 4.;
object.vertice_z [30] = .5;
object.vertice_x [31] = 3.;
object.vertice_y [31] = -3.5;
object.vertice_z [31] = .5;
object.vertice_x [32] = 3.75;
object.vertice_y [32] = -3.5;
object.vertice_z [32] = .5;
object.vertice_x [33] = 3.75;
object.vertice_y [33] = -4.;
object.vertice_z [33] = .5;
object.vertice_x [34] = .5;
object.vertice_y [34] = -4.;
object.vertice_z [34] = .5;
object.vertice_x [35] = .5;
object.vertice_y [35] = -3.5;
object.vertice_z [35] = .5;
object.vertice_x [36] = 1.25;
object.vertice_y [36] = -3.5;
object.vertice_z [36] = .5;
object.vertice_x [37] = -1.;
object.vertice_y [37] = -2.;
object.vertice_z [37] = .5;
object.vertice_x [38] = -.5;
object.vertice_y [38] = -1.;
object.vertice_z [38] = .5;
object.vertice_x [39] = 1.25;
object.vertice_y [39] = -1.;
object.vertice_z [39] = .5;
object.vertice_x [40] = 1.25;
object.vertice_y [40] = -2.;
object.vertice_z [40] = .5;
/* Now each polygon's vertice list just indexes the points */
/* listed above by the subscript of the vertice. Each polygon */
/* has a vertice count also. A four sided polygon is considered */
/* to have five vertices, the starting vertice, following around */
/* thru the second, third and fourth vertice, and ending by */
/* duplicating the first vertice as the last. */
/* This first polygon is a four sided polygon, as most are. */
object.polygon_vertice_count [1] = 5;
object.vertice_list [1] [1] = 1;
object.vertice_list [1] [2] = 21;
object.vertice_list [1] [3] = 22;
object.vertice_list [1] [4] = 2;
object.vertice_list [1] [5] = 1;
object.polygon_vertice_count [2] = 5;
object.vertice_list [2] [1] = 2;
object.vertice_list [2] [2] = 22;
object.vertice_list [2] [3] = 23;
object.vertice_list [2] [4] = 3;
object.vertice_list [2] [5] = 2;
object.polygon_vertice_count [3] = 5;
object.vertice_list [3] [1] = 3;
object.vertice_list [3] [2] = 23;
object.vertice_list [3] [3] = 24;
object.vertice_list [3] [4] = 4;
object.vertice_list [3] [5] = 3;
object.polygon_vertice_count [4] = 5;
object.vertice_list [4] [1] = 5;
object.vertice_list [4] [2] = 25;
object.vertice_list [4] [3] = 26;
object.vertice_list [4] [4] = 6;
object.vertice_list [4] [5] = 5;
object.polygon_vertice_count [5] = 5;
object.vertice_list [5] [1] = 6;
object.vertice_list [5] [2] = 26;
object.vertice_list [5] [3] = 27;
object.vertice_list [5] [4] = 7;
object.vertice_list [5] [5] = 6;
object.polygon_vertice_count [6] = 5;
object.vertice_list [6] [1] = 7;
object.vertice_list [6] [2] = 27;
object.vertice_list [6] [3] = 28;
object.vertice_list [6] [4] = 8;
object.vertice_list [6] [5] = 7;
object.polygon_vertice_count [7] = 5;
object.vertice_list [7] [1] = 8;
object.vertice_list [7] [2] = 28;
object.vertice_list [7] [3] = 21;
object.vertice_list [7] [4] = 1;
object.vertice_list [7] [5] = 8;
object.polygon_vertice_count [8] = 5;
object.vertice_list [8] [1] = 14;
object.vertice_list [8] [2] = 34;
object.vertice_list [8] [3] = 35;
object.vertice_list [8] [4] = 15;
object.vertice_list [8] [5] = 14;
object.polygon_vertice_count [9] = 5;
object.vertice_list [9] [1] = 15;
object.vertice_list [9] [2] = 35;
object.vertice_list [9] [3] = 36;
object.vertice_list [9] [4] = 16;
object.vertice_list [9] [5] = 15;
object.polygon_vertice_count [10] = 5;
object.vertice_list [10] [1] = 16;
object.vertice_list [10] [2] = 36;
object.vertice_list [10] [3] = 24;
object.vertice_list [10] [4] = 4;
object.vertice_list [10] [5] = 16;
object.polygon_vertice_count [11] = 5;
object.vertice_list [11] [1] = 4;
object.vertice_list [11] [2] = 24;
object.vertice_list [11] [3] = 29;
object.vertice_list [11] [4] = 9;
object.vertice_list [11] [5] = 4;
object.polygon_vertice_count [12] = 5;
object.vertice_list [12] [1] = 9;
object.vertice_list [12] [2] = 29;
object.vertice_list [12] [3] = 30;
object.vertice_list [12] [4] = 10;
object.vertice_list [12] [5] = 9;
object.polygon_vertice_count [13] = 5;
object.vertice_list [13] [1] = 10;
object.vertice_list [13] [2] = 30;
object.vertice_list [13] [3] = 31;
object.vertice_list [13] [4] = 11;
object.vertice_list [13] [5] = 10;
object.polygon_vertice_count [14] = 5;
object.vertice_list [14] [1] = 11;
object.vertice_list [14] [2] = 31;
object.vertice_list [14] [3] = 32;
object.vertice_list [14] [4] = 12;
object.vertice_list [14] [5] = 11;
object.polygon_vertice_count [15] = 5;
object.vertice_list [15] [1] = 12;
object.vertice_list [15] [2] = 32;
object.vertice_list [15] [3] = 33;
object.vertice_list [15] [4] = 13;
object.vertice_list [15] [5] = 12;
object.polygon_vertice_count [16] = 5;
object.vertice_list [16] [1] = 13;
object.vertice_list [16] [2] = 33;
object.vertice_list [16] [3] = 34;
object.vertice_list [16] [4] = 14;
object.vertice_list [16] [5] = 13;
object.polygon_vertice_count [17] = 5;
object.vertice_list [17] [1] = 18;
object.vertice_list [17] [2] = 38;
object.vertice_list [17] [3] = 39;
object.vertice_list [17] [4] = 19;
object.vertice_list [17] [5] = 18;
object.polygon_vertice_count [18] = 5;
object.vertice_list [18] [1] = 20;
object.vertice_list [18] [2] = 40;
object.vertice_list [18] [3] = 37;
object.vertice_list [18] [4] = 17;
object.vertice_list [18] [5] = 20;
object.polygon_vertice_count [19] = 5;
object.vertice_list [19] [1] = 17;
object.vertice_list [19] [2] = 18;
object.vertice_list [19] [3] = 19;
object.vertice_list [19] [4] = 20;
object.vertice_list [19] [5] = 17;
object.polygon_vertice_count [20] = 6;
object.vertice_list [20] [1] = 16;
object.vertice_list [20] [2] = 4;
object.vertice_list [20] [3] = 9;
object.vertice_list [20] [4] = 10;
object.vertice_list [20] [5] = 11;
object.vertice_list [20] [6] = 16;
object.polygon_vertice_count [21] = 5;
object.vertice_list [21] [1] = 3;
object.vertice_list [21] [2] = 4;
object.vertice_list [21] [3] = 5;
object.vertice_list [21] [4] = 6;
object.vertice_list [21] [5] = 3;
object.polygon_vertice_count [22] = 5;
object.vertice_list [22] [1] = 1;
object.vertice_list [22] [2] = 2;
object.vertice_list [22] [3] = 7;
object.vertice_list [22] [4] = 8;
object.vertice_list [22] [5] = 1;
object.polygon_vertice_count [23] = 5;
object.vertice_list [23] [1] = 14;
object.vertice_list [23] [2] = 15;
object.vertice_list [23] [3] = 12;
object.vertice_list [23] [4] = 13;
object.vertice_list [23] [5] = 14;
object.polygon_vertice_count [24] = 5;
object.vertice_list [24] [1] = 40;
object.vertice_list [24] [2] = 39;
object.vertice_list [24] [3] = 38;
object.vertice_list [24] [4] = 37;
object.vertice_list [24] [5] = 40;
object.polygon_vertice_count [25] = 6;
object.vertice_list [25] [1] = 31;
object.vertice_list [25] [2] = 30;
object.vertice_list [25] [3] = 29;
object.vertice_list [25] [4] = 24;
object.vertice_list [25] [5] = 36;
object.vertice_list [25] [6] = 31;
object.polygon_vertice_count [26] = 5;
object.vertice_list [26] [1] = 26;
object.vertice_list [26] [2] = 25;
object.vertice_list [26] [3] = 24;
object.vertice_list [26] [4] = 23;
object.vertice_list [26] [5] = 26;
object.polygon_vertice_count [27] = 5;
object.vertice_list [27] [1] = 28;
object.vertice_list [27] [2] = 27;
object.vertice_list [27] [3] = 22;
object.vertice_list [27] [4] = 21;
object.vertice_list [27] [5] = 28;
object.polygon_vertice_count [28] = 5;
object.vertice_list [28] [1] = 33;
object.vertice_list [28] [2] = 32;
object.vertice_list [28] [3] = 35;
object.vertice_list [28] [4] = 34;
object.vertice_list [28] [5] = 33;
/******* You shouldn't need to make changes past here, *******/
/* unless you want to change the file name to */
/* be more meaningful for your object. */
/* (Change in two places) */
/* Now the object is saved to a file */
/* Open file */
fp = fopen("a.obj","w");
/* The following fprintf statement puts the object file header to disk. */
/* The first '1' means there is 1 object in this file. */
/* The second value identifies which object this is in the object file. */
/* The '3' identifies this as an alpha object, built from polygons. */
/* Object '2' is a general polygonal object. Be sure to use a 2 or 3! */
/* Object types 2 and 3 are the only ones supported in A-Render v.3. */
/* After, the polygon and object counts are written to the file. */
fprintf(fp,"1 %d 3 %d %d",
this_object_id,
object.polygon_count,
object.vertice_count);
/* Now just save the object verticies! */
for (vertice_id=1;
vertice_id <= object.vertice_count; vertice_id++) {
fprintf(fp," %f %f %f",
object.vertice_x [vertice_id],
object.vertice_y [vertice_id],
object.vertice_z [vertice_id]);
}
/* And save the polygons. */
for (polygon_id=1;
polygon_id <= object.polygon_count; polygon_id++) {
fprintf(fp," %d",
object.polygon_vertice_count [polygon_id]);
for (vlist_id=1;
vlist_id <= object.polygon_vertice_count [polygon_id];
vlist_id++) {
fprintf(fp," %d",
object.vertice_list [polygon_id] [vlist_id]);
}
}
/* Close */
printf("\n");
fclose(fp);
printf("a.obj written\n");
}